package cn.com.guage.dtm.stat.controller;

import java.util.List;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.com.guage.dtm.common.annotation.Log;
import cn.com.guage.dtm.common.core.controller.BaseController;
import cn.com.guage.dtm.common.core.domain.AjaxResult;
import cn.com.guage.dtm.common.core.page.TableDataInfo;
import cn.com.guage.dtm.common.enums.BusinessType;
import cn.com.guage.dtm.common.utils.poi.ExcelUtil;
import cn.com.guage.dtm.stat.domain.CardEntity;
import cn.com.guage.dtm.stat.domain.StatTransReportDetail;
import cn.com.guage.dtm.stat.service.IStatTransReportDetailService;

/**
 * 数据迁移报告详情Controller
 * 
 * @author ruoyi
 * @date 2021-07-22
 */
@Controller
@RequestMapping("/stat/reportDetail")
public class StatTransReportDetailController extends BaseController
{
    private String prefix = "stat/reportDetail";

    @Autowired
    private IStatTransReportDetailService statTransReportDetailService;

    @RequiresPermissions("stat:reportDetail:view")
    @GetMapping()
    public String reportDetail()
    {
        return prefix + "/reportDetail";
    }

    /**
     * 查询数据迁移报告详情列表
     */
    @RequiresPermissions("stat:reportDetail:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(StatTransReportDetail statTransReportDetail)
    {
        startPage();
        List<StatTransReportDetail> list = statTransReportDetailService.selectStatTransReportDetailList(statTransReportDetail);
        return getDataTable(list);
    }

    /**
     * 导出数据迁移报告详情列表
     */
    @RequiresPermissions("stat:reportDetail:export")
    @Log(title = "数据迁移报告详情", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(StatTransReportDetail statTransReportDetail)
    {
        List<StatTransReportDetail> list = statTransReportDetailService.selectStatTransReportDetailList(statTransReportDetail);
        ExcelUtil<StatTransReportDetail> util = new ExcelUtil<StatTransReportDetail>(StatTransReportDetail.class);
        return util.exportExcel(list, "数据迁移报告详情数据");
    }

    /**
     * 新增数据迁移报告详情
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存数据迁移报告详情
     */
    @RequiresPermissions("stat:reportDetail:add")
    @Log(title = "数据迁移报告详情", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(StatTransReportDetail statTransReportDetail)
    {
        return toAjax(statTransReportDetailService.insertStatTransReportDetail(statTransReportDetail));
    }

    /**
     * 修改数据迁移报告详情
     */
    @GetMapping("/edit/{reportId}")
    public String edit(@PathVariable("reportId") Long reportId, ModelMap mmap)
    {
        StatTransReportDetail statTransReportDetail = statTransReportDetailService.selectStatTransReportDetailById(reportId);
        mmap.put("statTransReportDetail", statTransReportDetail);
        return prefix + "/edit";
    }

    /**
     * 修改保存数据迁移报告详情
     */
    @RequiresPermissions("stat:reportDetail:edit")
    @Log(title = "数据迁移报告详情", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(StatTransReportDetail statTransReportDetail)
    {
        return toAjax(statTransReportDetailService.updateStatTransReportDetail(statTransReportDetail));
    }

    /**
     * 删除数据迁移报告详情
     */
    @RequiresPermissions("stat:reportDetail:remove")
    @Log(title = "数据迁移报告详情", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(statTransReportDetailService.deleteStatTransReportDetailByIds(ids));
    }
    
    @PostMapping("/showStatTransReportDetailId")
  	@ResponseBody
  	public TableDataInfo showStatTransReportDetailId(StatTransReportDetail statTransReportDetail) {
    	StatTransReportDetail queryParams = new StatTransReportDetail();
  		queryParams.setTransReportId(statTransReportDetail.getTransReportId());
  		startPage();
  		List<StatTransReportDetail> list = statTransReportDetailService.selectStatTransReportDetailList(statTransReportDetail);
  		return getDataTable(list);
  	}
}
